package com.sam.library.document;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.io.File;

/**
 * @author wanghao
 * @date 2022/11/1.
 * @des
 */
public class DocumentActivity extends AppCompatActivity {

    protected RecyclerView header, content;
    private FileAdapter mFileAdapter;
    private HeaderAdapter mHeaderAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout._sam_activity_document);
        header = findViewById(R.id.header);
        content = findViewById(R.id.content);

        header.setLayoutManager(new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false));
        content.setLayoutManager(new LinearLayoutManager(this));

        mFileAdapter = new FileAdapter(new OnDirectoryClickListener() {
            @Override
            public void onDirectoryClick(File dir) {
                refreshDir(dir);
            }
        });
        content.setAdapter(mFileAdapter);

        mHeaderAdapter = new HeaderAdapter(new OnDirectoryClickListener() {
            @Override
            public void onDirectoryClick(File dir) {
                refreshDir(dir);
            }
        });
        header.setAdapter(mHeaderAdapter);

        refreshDir(getFilesDir());
//        refreshDir(getExternalCacheDir());

    }

    private void refreshDir(File dir) {
        if (dir != null) {
            mHeaderAdapter.setData(dir);
            mFileAdapter.setData(dir.listFiles());
        }
    }

}
